<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="关键字" prop="searchValue">
        <el-input
          v-model="queryParams.searchValue"
          placeholder="用户姓名搜索"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报告状态" prop="reportStatus">
        <el-select
          v-model="queryParams.reportStatus"
          placeholder="请选择报告状态"
          clearable
          @change="handleQuery"
        >
          <el-option
            v-for="dict in dict.type.report_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请机构" prop="companyId">
        <SelectCompany
          :defaultValue.sync="queryParams.companyId"
          placeholder="请选择申请机构"
          :companyType="0"
          @change="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务机构" prop="checkAgency">
        <SelectCompany
          :defaultValue.sync="queryParams.checkAgency"
          :isAll="true"
          placeholder="请选择服务机构"
          :companyType="0"
          @change="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      :data="tableList"
      v-loading="loading"
      style="width: 100%;"
      border
    >
      <el-table-column label="服务项目" align="center" width="200">
        <template slot-scope="{ row }">
          <div>{{ row.itemName }}</div>
          <!-- <div v-if="row.itemLine.checkNum">
            检验检查{{ row.itemLine.checkNum }}项
          </div>
          <div v-if="row.itemLine.drugNum">
            药品{{ row.itemLine.drugNum }}项
          </div>
          <div v-if="row.itemLine.otherNum">
            其它{{ row.itemLine.otherNum }}项
          </div> -->
        </template>
      </el-table-column>
      <el-table-column
        label="服务所属机构"
        prop="checkAgencyName"
        align="center"
        width="200"
      ></el-table-column>
      <el-table-column
        label="消费人"
        prop="checkUser"
        align="center"
      ></el-table-column>
      <el-table-column
        label="消费人电话"
        prop="userPhone"
        align="center"
        width="120px"
      ></el-table-column>
      <el-table-column
        label="报告状态"
        prop="reportStatus"
        align="center"
        width="120px"
      >
        <template slot-scope="{ row }">
          <dict-tag
            :options="dict.type.report_status"
            :value="row.reportStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="检测时间段"
        prop="reportCheckTime"
        align="center"
        width="175px"
      >
        <template slot-scope="{ row }">
          <span>{{ row.reportCheckTime || "-" }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="报告生成时间"
        prop="reportTime"
        align="center"
        width="180px"
      >
        <template slot-scope="{ row }">
          <span>{{ row.reportTime || "-" }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="开单申请人"
        prop="applyDoctor"
        align="center"
        width="120px"
      ></el-table-column>
      <el-table-column
        label="申请人所属机构"
        prop="companyName"
        align="center"
        width="200"
      ></el-table-column>

      <el-table-column label="关联订单号" align="center" width="210">
        <template slot-scope="{ row }">
          <span>{{ row.orderNo }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="开单时间"
        prop="createTime"
        align="center"
        width="180px"
      ></el-table-column>
      <el-table-column label="操作" align="center" width="170px" fixed="right">
        <template slot-scope="{ row }">
          <a
            v-if="row.reportStatus == 2"
            :href="row.reportUrl"
            target="_blank"
            style="color: #1890ff"
            class="fz-12"
          >
            <i class="el-icon-download pr-5" />
            <span>下载报告</span>
          </a>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { checkReportList } from "@/api/service";
import { numSub } from "@/utils/big/calculate.js";
import OrderDetails from "@/views/order/inspection/orderDetails";
import SelectCompany from "@/components/SelectCompany";

export default {
  name: "Report",
  dicts: ["order_status", "report_status"],
  components: {
    OrderDetails,
    SelectCompany,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        searchValue: "",
        reportStatus: null,
        companyId: undefined, // 申请机构
        checkAgency: undefined, // 服务机构
      },
      tableList: [],
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    numSub,
    getList() {
      checkReportList(this.queryParams).then((response) => {
        this.tableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  },
};
</script>
